package matchthreegame.handlers;

import java.lang.ref.WeakReference;

import matchthreegame.dataBase.DBManagerHelper;
import matchthreegame.extensions.MatchThreeGameZoneExtension;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.BaseClientRequestHandler;

public class UpdateMoneyRequestHandler extends BaseClientRequestHandler {

	public static final String MONEY_TO_UPDATE = "MTU";

	MatchThreeGameZoneExtension zoneExtension;

	@Override
	public void handleClientRequest(User sender, ISFSObject params) {

		zoneExtension = (MatchThreeGameZoneExtension)getParentExtension().getParentZone().getExtension();

		String senderName = sender.getName();
		int moneyToUpdate = params.getInt(MONEY_TO_UPDATE);

		WeakReference<DBManagerHelper> dbHelper = null;

		try {

			dbHelper = new WeakReference<DBManagerHelper>(zoneExtension.getDBHelper());

			dbHelper.get().updateMoneyForUser(moneyToUpdate, senderName);

		} catch (Exception e) {
			trace(e.getMessage().toString());
		}

	}

}
